
#include "sample_sys.h"
#include "sample_vin.h"
#include "sample_vout.h"
#include "sample_isp.h"
#include "sample_venc.h"
#include "sample_vdec.h"

int main(int argc, char **argv)
{

    int ret = -1;
    int start_mode = 0;

	printf("**********************************************************************\n");
	printf("* sgks mpi sample dec svn version: %s  build time: %s  \r\n",SVNREVISION,TIMESTAMP);
	printf("**********************************************************************\n");

    if (argc < 4)
    {
        printf("./sample_main <h264/mjpeg> <filename> <enc/dec>\n");
        return -1;
    }

    if(strcmp(argv[5], "dec") == 0)
    {
        /*start dec*/
        ret = sgks_mpi_sample_SysInit(SGKS_DSP_DECODE_MODE);
        if (ret != SGKS_SUCCESS)
            return ret;

        ret = sgks_mpi_sample_VoutInit(SGKS_VO_SRC_DEC, SGKS_VO_SRC_ENC);
        if (ret != SGKS_SUCCESS)
            return ret;

        ret =  sgks_mpi_sys_Start();
        if (ret != SGKS_SUCCESS)
            return ret;
    }
    else
    {
        /*start enc*/
        ret = sgks_mpi_sample_SysInit(SGKS_DSP_ENCODE_MODE);
        if (ret != SGKS_SUCCESS)
            return ret;

        ret = sgks_mpi_sample_VinInit();
        if (ret != SGKS_SUCCESS)
            return ret;

        ret = sgks_mpi_sample_IspInit();
        if (ret != SGKS_SUCCESS)
            return ret;

        ret = sgks_mpi_sample_VoutInit(SGKS_VO_SRC_ENC, SGKS_VO_SRC_ENC);
        if (ret != SGKS_SUCCESS)
            return ret;

        ret =  sgks_mpi_sample_venc_setting(SENSOR_DATA_ENCODE_TEST);
        if (ret != SGKS_SUCCESS)
            return ret;

        ret =  sgks_mpi_sys_Start();
        if (ret != SGKS_SUCCESS)
            return ret;

        ret = sgks_mpi_sample_venc_start();
        if (ret != SGKS_SUCCESS)
            return ret;
#if 0
        ret = sgks_mpi_sample_venc_test();
        if (ret != SGKS_SUCCESS)
            return ret;
#endif
        sleep(10);

        ret = sgks_mpi_sample_venc_stop();
        if (ret != SGKS_SUCCESS)
            return ret;

        start_mode = 1;

    }

    sgks_mpi_sys_ViBindVo(1,0);

    if(strcmp(argv[1], "h264") == 0)
    {

        ret = sgks_mpi_sample_EnableH264Vdec(argv[2], start_mode);
        if (ret != SGKS_SUCCESS)
            return ret;

    }
    else if(strcmp(argv[1], "mjpeg") == 0)
    {

        ret = sgks_mpi_sample_EnableMjpegVdec(argv[2], start_mode);
        if (ret != SGKS_SUCCESS)
            return ret;

    }

#if 0
    while(1)
    {
        // sgks_mpi_vi_init(&vi_dev);
        //sgks_mpi_vi_deinit(&vi_dev);
        sleep(3);
    }
#endif

    return SGKS_SUCCESS;


}




